package main

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
)

type student struct {
	Name string `json:"name" xml:"xm"` //结构体标签名不能随便定义，要有对应的数据源
	Age  int    `json:"age" xml:"nl"`
}

func main() {
	str := `{"name":"ZL","age":9000}`
	var stu1 student
	err := json.Unmarshal([]byte(str), &stu1)
	if err != nil {
		fmt.Printf("反序列化失败，err:%v\n", err)
	}
	fmt.Printf("%#v\n", stu1)

	xmlstr :=
		`<?xml version="1.0" encoding="UTF-8"?>` +
			`<config>` +
			`<xm>zjd</xm>` +
			`<nl>33</nl>` +
			`</config>`
	var stu2 student
	err1 := xml.Unmarshal([]byte(xmlstr), &stu2)
	if err1 != nil {
		fmt.Printf("反序列化失败，err1:%v\n", err1)
	}
	fmt.Printf("%#v\n", stu2)

}
